// pages/record/record.js
import * as echarts from '../../ec-canvas/echarts'
const app = getApp();
var dateRec = [];
var scoreRec = [];
function initChart(canvas, width, height) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height
  });
  canvas.setChart(chart);

  var option = {
    xAxis: {
      type: 'category',
      data: dateRec
    },
    yAxis: {
      type: 'value'
    },
    series: [{
      data: scoreRec,
      type: 'line'
    }]
  };

  chart.setOption(option);
  return chart;
}

Page({

  /**
   * 页面的初始数据
   */
  data: {
    hid: false,
    ec: {
      onInit: initChart
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var markRec ={}

    wx.getStorage({
      key: 'markrecord',
      success: function (res) {
        var markRec = res.data;
        console.log(markRec);
        dateRec = markRec.dateRec;
        scoreRec = markRec.scoreRec;
      },
      fail: function (res) {
        //说明没有数据
        //console.log(res)
        that.setData({
          hid: true
        })
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})